package com.yaorange.module.system.controller;

import com.yaorange.module.system.service.SysPermissionService;
import com.yaorange.module.vo.SysPermissionTreeVo;
import com.yaorange.pojo.SysPermission;
import com.yaorange.response.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 15332
 * @version 1.0
 * @date 2025/6/19 15:20
 * @description 权限控制器
 */
@RestController
@RequestMapping("/sys/permission")
public class SysPermissionController {
  @Autowired
  private SysPermissionService service;

  /**
   * 获取权限树
   */
  @GetMapping
  public Result<List<SysPermissionTreeVo>> getPermTree(){
    return Result.success(service.selectPermTree());
  }
  /**
   *  获取权限集合
   */
  @GetMapping("/perm")
  public Result<List<SysPermission>> getPerm(){
    return Result.success(service.selectPerm());
  }
  /**
   * 根据Id获取到这个权限的对象
   */
  @GetMapping("/perm/{id}")
  public Result<SysPermission> getPermissionById(@PathVariable("id") Long id){
    SysPermission sysPermission = service.selectPermissionById(id);
    return Result.success(sysPermission);
  }

  /**
   * 根据ID获取到这个用户的权限
   */
  @GetMapping("{id}")
  public Result<List<Long>> getPermById(@PathVariable("id") Long id){
    return Result.success(service.selectPermById(id));
  }

  /**
   * 处理权限启用和禁用
   */
  @PutMapping("/{id}/{status}")
  public Result<?> permStatus(@PathVariable("id") Long id,@PathVariable("status") Long permStatus){
    service.updateStatus(id,permStatus);
    return Result.success();
  }

}
